﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Computer_Manager.DTO;
using System.Data;

namespace Computer_Manager.DAL
{
    public class DAL_roles
    {
        DbProvider db = new DbProvider();
        SqlCommand cmd;
        public void roles_insert(DTO_roles dt)
        {
            cmd = new SqlCommand("roles_Insert", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@role_name", SqlDbType.NVarChar).Value = dt.role_name;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void roles_Update(DTO_roles dt)
        {
            cmd = new SqlCommand("roles_Update", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@role_id", SqlDbType.Int).Value = dt.role_id;
            cmd.Parameters.Add("@role_name", SqlDbType.NVarChar).Value = dt.role_name;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        public void roles_Delete(DTO_roles dt)
        {
            cmd = new SqlCommand("roles_Delete", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@role_id", SqlDbType.Int).Value = dt.role_id;
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            db.getConn().Close();
        }
        public DataTable GetAll()
        {
            SqlDataAdapter adapter = new SqlDataAdapter("roles_SelectAll", db.getConn());
            DataTable table = new DataTable();
            adapter.Fill(table);
            adapter.Dispose();
            return table;
        }
        public DataTable GetByID(DTO_roles dt)
        {
            cmd = new SqlCommand("roles_GetByID", db.getConn());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@role_id", SqlDbType.Int).Value = dt.role_id;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }

    }
}
